﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "IStructureVariableSectionWall.h"
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "StructureWall.h"
#include "DbDataSchema.h"

namespace gcmp
{
    class IParameter;

    class StructureVariableSectionWall : public NdbObjectSchematic, public IExternalData, public IStructureVariableSectionWall
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, StructureVariableSectionWall, gcmp::NdbObjectSchematic, C711C120 - 21F1 - 4629 - AA3D - 1EB3705375FA, gmstructure, IExternalData)
            DATA(OwnerPtr<StructureWall>, BaseData)
        DBOBJECT_DATA_END

    public:
        static StructureVariableSectionWall *Create(const StructureWallInput *pInput);
        static const StructureVariableSectionWall *Get(const IInstance *pInstance);
        static StructureVariableSectionWall *Get(IInstance *pInstance);

        const StructureWall* GetBaseData() const { return GetBaseData__().get(); }
        StructureWall* GetBaseDataFW() { return GetBaseDataFW__().get(); }

    public:
        DECLARE_STRUCTURE_INSTANCE_METHODS;

        virtual double GetLength() const override { return GetBaseData__()->GetLength(); };
        virtual double GetArea() const override { return GetBaseData__()->GetArea(); };
        virtual double GetVolume() const override { return GetBaseData__()->GetVolume(); };
        virtual RegenDataId GetWallShapeChangedRdId() const override { return GetBaseData__()->GetWallShapeChangedRdId(); }

        bool CustomizeParameters();

    private:
        static IInstance* CreateStraightVariableSectionWall(const StructureWallInput* pInput);
        static StructureVariableSectionWall* RegisterExternalData(IInstance* pInstance, const StructureWallInput* pInput);

    private:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override { return m_BaseData->SetOwnerElement(pOwnerElement); };
        virtual IElement* GetOwnerElement() override { return m_BaseData->GetOwnerElement(); };
        virtual const IElement* GetOwnerElement() const override { return GetBaseData__()->GetOwnerElement(); };
        IDocument* GetDocument() const { return GetBaseData__()->GetDocument(); };
        ElementId GetOwnerElementId() const { return GetBaseData__()->GetOwnerElementId(); };
        virtual NdbObject* GetTopOwnerObject() const override;

        bool SetVolume(double volume) { return GetBaseDataFW__()->SetVolume(volume); };
        bool SetLength(double length) { return GetBaseDataFW__()->SetLength(length); };
        bool SetArea(double area) { return GetBaseDataFW__()->SetArea(area); };

    private:
        virtual void ReportElementIds(std::set<ElementId>* pElementIds, std::unordered_map<ElementId, std::vector<std::wstring>, ElementIdHash>* pPaths,
            std::vector<std::wstring>* pCurrentPath) const final {}
        virtual void ReplaceElementIds(const std::unordered_map<ElementId, ElementId, ElementIdHash>& oldToNewMap) final {}

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override;

        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr) override;
        virtual bool IsParameterModifiable(int paramDefId) const override;

        virtual void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const override;
        virtual void UpdateAfterCopy(const ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override { return true; }

    };
}
